package com.vmladenov.cook.core.loaders;

import java.util.ArrayList;

import com.vmladenov.cook.core.db.ISmallPreviewListRepository;
import com.vmladenov.cook.core.html.SmallPreview;

public class Loader extends ISmallPreviewLoader
{
	protected final Integer pageSize = 10;
	protected long currentRow = 0;
	protected long rowCount = 0;
	private ISmallPreviewListRepository repository;

	public Boolean hasMore()
	{
		if (this.rowCount == 0) rowCount = getRepository().getRowCount();
		return currentRow < this.rowCount;
	}

	@Override
	public ArrayList<SmallPreview> getNextData()
	{
		long startRow = currentRow;
		ArrayList<SmallPreview> data = getRepository().getPreviews(startRow, sorting);
		currentRow = startRow + pageSize;
		return data;
	}

	public void setRepository(ISmallPreviewListRepository repository)
	{
		this.repository = repository;
	}

	public ISmallPreviewListRepository getRepository()
	{
		return repository;
	}
}
